package za.co.chris.traintimes.beans;

import java.util.List;

import za.co.chris.traintimes.R;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ResultLayout extends LinearLayout {

	LayoutInflater layoutInflater;
	View inflatedView;
	TextView fromStationText;
	TextView toStationText;
	private final LinearLayout timesLayout;
	private final List<TimeElement> times;

	public ResultLayout(Context context, String fromStation, String toStation, List<TimeElement> times) {
		super(context);
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflatedView = layoutInflater.inflate(R.layout.result_layout, this);
		fromStationText = (TextView) findViewById(R.id.fromStationResult);
		toStationText = (TextView) findViewById(R.id.toStationResult);
		fromStationText.setText(fromStation);
		toStationText.setText(toStation);
		timesLayout = (LinearLayout) findViewById(R.id.timesLayout);
		this.times = times;
		for (TimeElement time : times) {
			timesLayout.addView(time);
			timesLayout.addView(getSpacer());
		}
	}

	private View getSpacer() {
		View spacer = new View(this.getContext());
		spacer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
		spacer.setBackgroundColor(Color.DKGRAY);
		return spacer;
	}

	public TimeElement getTime(int index) {
		return times.get(index);
	}
}
